<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Cache;

class Cases extends Controller
{
	public function anli_index()
	{
        $this->types();
        $list = Db::table('anli')->select();
        $this->assign('list',$list);
		return $this->fetch();
	}
	public function types()
    {
        //获取一级分类
        $type = Db::table('type')->where(array('pid'=>0))->select();
        $type2 = array();
        $type3 = array();
        foreach($type as $key=>$value){
            $type[$key]['child']=array();//二级分类的名字
            $type2=Db::table('type')->where("pid=".$value['id'])->select();//获取二级分类

            foreach($type2 as $k=>$v){
                
              

                array_push($type[$key]['child'],$v);//合并一级与二级分类
                $type[$key]['child'][$k]['child2']=array();////三级分类的名字
               
                    $type3=Db::table('type')->where("pid=".$v['id'])->select();//获取三级分类
                    foreach($type3 as $v2){


                          array_push($type[$key]['child'][$k]['child2'],$v2);//合并一级二级三级分类
                    }
                  
               
            }

        }
        $this->assign('type',$type);
    }
}